package cn.xiaobai.core.utils;

import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @Author yangdaji
 * @Date 2023/12/11
 * @PackageName cn.xiaobai.core.utils
 * @ClassName JsonUtils
 */
public class JsonUtils {

    private static ObjectMapper objectMapper = new ObjectMapper();

    public static <T> T toBean(String json, Class<T> tClass) {
        if (JSONUtil.isTypeJSON(json)) {
            try {
                return objectMapper.readValue(json, tClass);
            } catch (JsonProcessingException e) {

            }
        }
        return null;
    }
}
